package com.mogu_soup.entity;

import com.mogu_soup.util.MyUtil;

import java.awt.*;

/**
 * Version: 2.1
 * Author: TangJun
 * Date: 2024-08-03
 * Note:
 */
public class Bomb extends Entity{
    private static final int BOMB_COUNT = 15;//图片的个数

    public static final Image DESTROY = MyUtil.createImage("resource\\bomb\\destroy.gif");
    private static final Image[] BOMB;
    static {
        BOMB = new Image[BOMB_COUNT];
        for (int i = 0; i < BOMB.length; i++) {
            BOMB[i] = MyUtil.createImage("resource\\bomb\\bomb" + i + ".png");
        }
    }

    private int index;

    //构造方法
    public Bomb(int x, int y, int size) {
        this.x = x;
        this.y = y;
        this.size = size;
        this.isLive = true;
        this.index = 0;
    }
    //修改参数
    public void set(int x, int y, int size) {
        this.x = x;
        this.y = y;
        this.size = size + 10;
        this.isLive = true;
        this.index = 0;
    }

    //绘制爆炸效果
    @Override
    public void draw(Graphics g) {
        if (index < BOMB_COUNT) {
            g.drawImage(BOMB[index++], x - size / 2, y - size / 2 - 10, size, size,  null);
        } else {
            isLive = false;
        }
    }

}
